package work1;

import java.util.List;
import java.util.Scanner;

public class StudentManage {
    Scanner scanner=new Scanner(System.in);

    //添加
    public boolean add( List<Student> list){
        System.out.println("添加学生信息:");
        System.out.println("请输入ID");
        String s1=scanner.next();
        System.out.println("请输入姓名");
        String s2=scanner.next();
        System.out.println("请输入性别");
        String s3=scanner.next();
        System.out.println("请输入系名");
        String s4=scanner.next();
        System.out.println("请输入年级");
        String s5=scanner.next();
        Student student=new Student(s1,s2,s3,s4,s5);
        list.add(student);
        System.out.println("添加成功");
        return true;
    }
    //删除
    public boolean delete(List<Student>list){
        show(list);//先显示一遍所有的学生信息
        System.out.println("请输入你要删除的学生ID:");
        String s=scanner.next();
        for (int i = 0; i <list.size() ; i++) {//遍历集合
            Student student=list.get(i);//获取当前学生对象
            if(student.getID().equals(s)){//若ID相等,则删除
                list.remove(student);
                System.out.println("删除成功");
                return true;
            }
        }
        return false;//没找到,FALSE
    }
    //修改
    public boolean revise(List<Student> list){
        show(list);//先显示一遍所以信息
        System.out.println("请输入你要修改的学生ID");
        String s=scanner.next();
        for (int i = 0; i <list.size() ; i++) {
            if(list.get(i).getID().equals(s)){//找到要修改学生的下标
                System.out.println("请输入修改后的学生ID");
                String s1=scanner.next();
                System.out.println("请输入修改后的学生姓名");
                String s2=scanner.next();
                System.out.println("请输入修改后的性别");
                String s3=scanner.next();
                System.out.println("请输入修改后的系名");
                String s4=scanner.next();
                System.out.println("请输入修改后的年级");
                String s5=scanner.next();
                Student student=new Student(s1,s2,s3,s4,s5);//修改后的学生对象
                list.set(i,student);//替换修改后的学生对象
                System.out.println("修改成功");
                return true;
            }
        }
        return false;
    }
    //查询
    public boolean select(List<Student> list){
        System.out.println("查询");
        System.out.println("请输入你要查询的学生ID");
        String s=scanner.next();
        for (int i = 0; i <list.size() ; i++) {//遍历list集合
            Student student=list.get(i);//获取学生对象
            if (student.getID().equals(s)){//若ID相等,则找到了
                System.out.println("找到了:"+student);//输出
                return true;
            }
        }
        System.out.println("没有找到当前ID对应的学生");
        return false;//没找到,FALSE
    }
    //显示所有学生信息
    public void show(List<Student> list){
        for (Student student:list){//遍历集合
            System.out.println(student);
        }
    }
    //退出
    public void exit(){
        System.exit(0);
    }
}
